let themeColorOptions = [
  { color: "#63b359", name: "Color010", fontColor: "#ffffff" },
  { color: "#2c9f67", name: "Color020", fontColor: "#ffffff" },
  { color: "#509fc9", name: "Color030", fontColor: "#ffffff" },
  { color: "#5885cf", name: "Color040", fontColor: "#ffffff" },
  { color: "#9062c0", name: "Color050", fontColor: "#ffffff" },
  { color: "#d09a45", name: "Color060", fontColor: "#ffffff" },
  { color: "#e4b138", name: "Color070", fontColor: "#000000" },
  { color: "#ee903c", name: "Color080", fontColor: "#ffffff" },
  { color: "#f08500", name: "Color081", fontColor: "#ffffff" },
  { color: "#a9d92d", name: "Color082", fontColor: "#000000" },
  { color: "#dd6549", name: "Color090", fontColor: "#ffffff" },
  { color: "#cc463d", name: "Color100", fontColor: "#ffffff" },
  { color: "#cf3e36", name: "Color101", fontColor: "#ffffff" },
  { color: "#5e6671", name: "Color102", fontColor: "#ffffff" },
  { color: "#fcb142", name: "Color103", fontColor: "#ffffff" },
  { color: "#f56C6C", name: "Color103", fontColor: "#ffffff" },
  {
    "color": "#5E6671",
    "name": "Color102",
    "fontColor": "#ffffff"
  }
]

export default {
  HexToRGB(color, opacity) {
    let newColor = 'rgba(';

    //判断是三位还是六位
    if (color.length === 4) {
      let arry = [];

      for (let i = 1; i < color.length; i++) {
        arry.push(parseInt("0x" + color[i] + color[i]));
      }

      arry.forEach(function (item) {
        newColor += item + ', ';
      });
      newColor += opacity / 100 + ')';
      return newColor;
    } else {
      let arry = [];

      for (let i = 1; i < color.length; i += 2) {
        arry.push(parseInt("0x" + color.slice(i, i + 2)));
      }

      arry.forEach(function (item) {
        newColor += item + ', ';
      });
      newColor += opacity / 100 + ')';

      return newColor;
    }
  },
  getThemeObj(colorName) {
    for (let i = 0; i <= themeColorOptions.length; i++) {
      if (themeColorOptions[i].name === colorName) {
        return themeColorOptions[i]
      }
    }
  },
  getTitleColor(color) {
    for (let i = 0; i <= themeColorOptions.length; i++) {
      if (themeColorOptions[i] && themeColorOptions[i].color === color) {
        return themeColorOptions[i].fontColor
      }
    }
  }
}
